package com.yzb.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.DispatcherServlet;

@Component
public class MyServlet implements ApplicationContextAware {
    private static ApplicationContext context;
    //使用ApplicationContextAware让Spring容器传递自己生成的ApplicationContext给我们
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context=applicationContext;
    }
    //将DispatcherServlet加载到上下文中
    public static DispatcherServlet getDispatcherServlet(){
        return context.getBean(DispatcherServlet.class);
    }
}
